/*
 *  Copyright (C) 2009 Dominik Psenner, Christoph Caks
 * 
 *   This file is part of project-blog.
 *
 *  project-blog is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  project-blog is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with project-blog.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.blog.model;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;

/*
 * @dominik: don't touch this!
 * 
 * TODO add tags support
 */

/**
 * 
 * @author Christoph Caks
 * 
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Article implements Serializable {
	
	private static final long serialVersionUID = 6006684946885629156L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key id;
	
	@Persistent
	private Blog blog;
	
	@Persistent
	private Text source;
	
	@Persistent
	private Text content;
	
	// @Persistent
	// private Set<Key> tagsKeys = new HashSet<Key>( );
	
	// private Set<Tag> tags = new HashSet<Tag>( );
	
	@Persistent
	private String title;
	
	@Persistent
	private Date creation;
	
	@Persistent
	private Date lastUpdate;
	
	@Persistent
	private boolean compiled;
	
	public Blog getBlog() {
		return blog;
	}
	
	public void setBlog(final Blog blog) {
		this.blog = blog;
	}
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(final String title) {
		this.title = title;
	}
	
	public String getSource() {
		if (source == null) {
			source = new Text("");
		}
		return source.getValue();
	}
	
	public void setSource(final String source) {
		this.source = new Text(source);
	}
	
	public String getContent() {
		if (content == null) {
			content = new Text("");
		}
		return content.getValue();
	}
	
	public Date getCreation() {
		return creation;
	}
	
	public void setCreation(final Date creation) {
		this.creation = creation;
	}
	
	public Key getId() {
		return id;
	}
	
	public Date getLastUpdate() {
		return lastUpdate;
	}
	
	public void setLastUpdate(final Date lastUpdate) {
		this.lastUpdate = lastUpdate;
	}
	
	public void setCompiled(final boolean compiled) {
		this.compiled = compiled;
	}
	
	public boolean isCompiled() {
		return compiled;
	}
	
	// public void addTag( Tag t ) {
	// tags.add(t);
	// }
	//	
	// public void removeTag( Tag t ) {
	// tags.remove(t);
	// }
	//	
	// public void emptyTags( ) {
	// tags.clear();
	// }
	//	
	// public Set<Tag> getTags() {
	// return Collections.unmodifiableSet(tags);
	// }
	//	
	// public void setTags(Set<Tag> tags) {
	// this.tags = tags;
	// }
	
	public void setContent(final String content) {
		this.content = new Text(content);
	}
	
}
